package com.powernode.settings.controller;

import com.powernode.commons.utils.ResponseData;
import com.powernode.settings.bean.DicTypeBean;
import com.powernode.settings.service.DicTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;

import java.beans.PropertyEditorSupport;
import java.util.Date;

@RestController
@RequestMapping("type")
@Api(tags = "字典类型维护")
public class DicTypeController {
    @Autowired
    private DicTypeService service;
    @GetMapping("ok")
    public String ok(String aaa,Date birth){
        System.out.println("aaa="+aaa);
        System.out.println("date="+birth);
        return "success";
    }


    @GetMapping
    @ApiOperation("分页显示所有的字典类型")
    public ResponseData  page(@RequestParam(required = false,defaultValue = "1")Integer pageNum,
                              @RequestParam(required = false,defaultValue = "5") Integer pageSize){
        return service.findAll(pageNum,pageSize);
    }

    @PostMapping
    @ApiOperation("添加字典类型")
    public ResponseData add(@RequestBody DicTypeBean type){
        return service.addType(type);
    }

    @PutMapping
    @ApiOperation("根据主键code修改字典类型")
    public ResponseData edit(@RequestBody DicTypeBean type){
        return service.modifyTypeByCode(type);
    }


    @DeleteMapping
    @ApiOperation("根据主键code单个或批量删除")
    public ResponseData deleteByCodes(@ApiParam("主键code,如果有多个用逗号隔开") String codes){
        return service.removeTypeByCodes(codes);
    }


}
